package model

import "gorm.io/gorm"

type Comment struct {
	Model
	Content   string `json:"content,omitempty"`
	UserID    uint   `json:"user_id,omitempty"`
	PictureID uint   `json:"picture_id,omitempty"`
}

func (c Comment) TableName() string {
	return "img_comment"
}

func (c Comment) Create(db *gorm.DB) error {
	return db.Create(&c).Error
}

func (c Comment) Update(db *gorm.DB) error {
	return db.Model(&c).Updates(&c).Error
}

func (c Comment) Get(db *gorm.DB) (Comment, error) {
	var comment Comment
	err := db.Where(&c).First(&comment).Error
	return comment, err
}

func (c Comment) List(db *gorm.DB, pageOffset int, pageSize int) ([]*Comment, error) {
	var categorys []*Comment
	err := db.Where(&c).Offset(pageOffset).Limit(pageSize).Find(&categorys).Error
	return categorys, err
}

func (c Comment) Delete(db *gorm.DB) error {
	return db.Delete(&c).Error
}

func (c Comment) Count(db *gorm.DB) (int, error) {
	var count int64
	err := db.Model(&c).Where(&c).Count(&count).Error
	return int(count), err
}
